package cn.jasonone.listener;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class MyHttpSessionListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent se) {
		ServletContext application = se.getSession().getServletContext();
		Integer count = (Integer) application.getAttribute("COUNT");
		count = count == null ? 1 : count + 1;
		application.setAttribute("COUNT", count);
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		ServletContext application = se.getSession().getServletContext();
		Integer count = (Integer) application.getAttribute("COUNT");
		count = count == null ? 0 : count - 1;
		application.setAttribute("COUNT", count);
	}

}
